package com.smbms.controller;

import com.smbms.entity.Provider;
import com.smbms.entity.User;
import com.smbms.service.ProviderService;
import com.smbms.service.UserService;
import com.smbms.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.Date;
import java.util.List;

/**
 * 供应商控制层
 */
@Controller
@RequestMapping("/api/provider")
public class ProviderController {

    @Autowired
    private ProviderService providerService;

    /**
     * 获取所有的供应商列表
     * @return
     */
    @RequestMapping("getList")
    @ResponseBody
    public Result getList(Provider user){
        List<Provider> userList=this.providerService.getList(user);
        return Result.reOk("查询成功",userList);
    }


    /**
     * 查询当前用户
     * @return
     */
    @RequestMapping("getId")
    @ResponseBody
    public Result getId(Integer id){
        Provider provider=this.providerService.getId(id);
        return Result.reOk("查询成功",provider);
    }

    /**
     * 新增供应商
     * @return
     */
    @RequestMapping("save")
    @ResponseBody
    public Result save(Provider user){
        user.setCreationDate(new Date());
        return this.providerService.save(user);
    }

    /**
     * 修改供应商
     * @return
     */
    @RequestMapping("update")
    @ResponseBody
    public Result update(Provider user){
        user.setModifyDate(new Date());
        return this.providerService.update(user);
    }


}
